<?php
require_once $_SESSION["app_root"]."config/app.config.php";
class User
{
    public $ID;
    public $Email;
    public $FirstName;
    public $LastName;
    public $Role = "guest";
	public $WorkingDomain;
	public $Domains;
	protected $Password;

    function __construct()
    {
        	//echo "<br />construct";
    }

    function __call($method, $arguments)
    {
    	/* dynamic setters and getters
        $prefix = strtolower(substr($method, 0, 3));
        $property = strtolower(substr($method, 3));
        if ( empty($prefix) || empty($property))
        {
            return;
        }
        if ($prefix == "get" && isset ($this->$property))
        {
            return $this->$property;
        }
        if ($prefix == "set")
        {
            $this->$property = $arguments[0];
        }
        */
    }
    public function User($id, $email, $first_name, $last_name, $role)
    {
        $this->ID = $id;
        $this->Email = $email;
        $this->FirstName = $first_name;
        $this->LastName = $last_name;
    }
	
	public function Login($user){
		$db = new AppDatabase();
			$exists = $db->getRow("users", "*" ,array("email"=>$user->Email, "password" => $user->Password));
		$db -> close();
		if($exists){
			$AuthUser = new User();
			$AuthUser->setID($exists['id']);
			$AuthUser->setWorkingDomain("");
			$AuthUser->setEmail($exists['email']);
			$AuthUser->setFirstName($exists['first_name']);
			$AuthUser->setLastName($exists['last_name']);
			$AuthUser->setRole($exists['role']);
			$_SESSION['user'] = $AuthUser;
		}
		return $exists;
	}

    public function getByID($id)
    {

    }

    public function isGuest()
    {

    }

    public function isUser()
    {

    }

    public function isSuperUser()
    {

    }

    public function isSysAdmin()
    {

    }

    public function isRoot()
    {

    }

    /**
     * Gets $Domains.
     * @see BLL_User::$Domains
     */
    public function getDomains()
    {
        return $this->Domains;
    }
    
    /**
     * Sets $Domains.
     * @param object $Domains
     * @see BLL_User::$Domains
     */
    public function setDomains($Domains)
    {
        $this->Domains = $Domains;
    }
    
    /**
     * Gets $Email.
     * @see BLL_User::$Email
     */
    public function getEmail()
    {
        return $this->Email;
    }
    
    /**
     * Sets $Email.
     * @param object $Email
     * @see BLL_User::$Email
     */
    public function setEmail($Email)
    {
        $this->Email = $Email;
    }

    /**
     * Gets $Password.
     * @see User::$Password
     */
    public function getPassword()
    {
        return $this->Password;
    }
    
    /**
     * Sets $Password.
     * @param object $Password
     * @see User::$Password
     */
    public function setPassword($Password)
    {
        $this->Password = md5($Password);
    }
    
    /**
     * Gets $FirstName.
     * @see BLL_User::$FirstName
     */
    public function getFirstName()
    {
        return $this->FirstName;
    }
    
    /**
     * Sets $FirstName.
     * @param object $FirstName
     * @see BLL_User::$FirstName
     */
    public function setFirstName($FirstName)
    {
        $this->FirstName = $FirstName;
    }
    
    /**
     * Gets $ID.
     * @see BLL_User::$ID
     */
    public function getID()
    {
        return $this->ID;
    }
    
    /**
     * Sets $ID.
     * @param object $ID
     * @see BLL_User::$ID
     */
    public function setID($ID)
    {
        $this->ID = $ID;
    }
    
    /**
     * Gets $LastName.
     * @see BLL_User::$LastName
     */
    public function getLastName()
    {
        return $this->LastName;
    }
    
    /**
     * Sets $LastName.
     * @param object $LastName
     * @see BLL_User::$LastName
     */
    public function setLastName($LastName)
    {
        $this->LastName = $LastName;
    }
    
    /**
     * Gets $Role.
     * @see BLL_User::$Role
     */
    public function getRole()
    {
        return $this->Role;
    }
    
    /**
     * Sets $Role.
     * @param object $Role
     * @see BLL_User::$Role
     */
    public function setRole($Role)
    {
        $this->Role = $Role;
    }
    
    /**
     * Gets $WorkingDomain.
     * @see BLL_User::$WorkingDomain
     */
    public function getWorkingDomain()
    {
        return $this->WorkingDomain;
    }
    
    /**
     * Sets $WorkingDomain.
     * @param object $WorkingDomain
     * @see BLL_User::$WorkingDomain
     */
    public function setWorkingDomain($WorkingDomain)
    {
        $this->WorkingDomain = $WorkingDomain;
    }

    function __destruct()
    {
        //echo "<br />destruct";
    }
}

?>
